package com.xxc.controller;

import com.xxc.dto.StudentRequestDTO;
import com.xxc.dto.StudentResponseDTO;
import com.xxc.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author xiangcheng
 * @version 2022/6/22 11:30
 * @since JDK8
 */
@RestController
@RequestMapping("/students")
@Slf4j
public class StudentController {
    private final StudentService studentService;

    @Autowired
    public StudentController(StudentService studentService) {
        this.studentService = studentService;
    }


    @GetMapping
    public List<StudentResponseDTO> queryAll(){
        return studentService.queryAll();
    }

    @PostMapping
    public StudentResponseDTO insert(@RequestBody StudentRequestDTO studentRequest){
        log.debug("班级id：{}",studentRequest.getClazzId());
        log.debug("城市id：{}",studentRequest.getCityId());
        log.debug("小组id：{}",studentRequest.getGroupId());
        if (studentRequest.getTagIds() != null){
            studentRequest.getTagIds().forEach(id -> {
                log.info("标签id：{}",id);
            });
        }
        return studentService.insert(studentRequest);
    }
}
